package com.taldh.algorithm.数学;

import org.junit.Assert;
import org.junit.Test;

public class IsPowerOfTwo {
    public boolean isPowerOfTwo(int n) {
        if (n == 0) {
            return false;
        }
        int i = n & (~n + 1);
        return i == n;
    }

    @Test
    public void test() {
        Assert.assertTrue(isPowerOfTwo(8));
    }

    @Test
    public void test1() {
        Assert.assertFalse(isPowerOfTwo(1073741825));
    }
}